<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- <ul> -->
      <!-- <li v-for="(item, index) in list" :key="index">{{ item.title }}</li> -->
      <!-- </ul> -->
      <child :list="list"></child>
    </div>

    <script src="../../Vue.js"></script>
    <script>
      const Child = {
        props: ["list"],
        // name选项允许组件调用自己，递归组件
        name: "Child",
        template: `
          <ul>
            <li v-for="(item, index) in list" :key="index">
              {{ item.title }}
              <child :list="item.children" v-if="item.children"></child>
            </li>
          </ul>
        `,
      };

      new Vue({
        el: "#app",
        components: {
          Child,
        },
        data: {
          list: [
            {
              title: "浙江省",
              children: [
                {
                  title: "杭州市",
                  children: [
                    {
                      title: "西湖区",
                    },
                    {
                      title: "江干区",
                      children: [
                        {
                          title: "九堡街道",
                        },
                      ],
                    },
                  ],
                },
                {
                  title: "宁波市",
                },
              ],
            },
            {
              title: "江苏省",
              children: [
                {
                  title: "南京市",
                },
                {
                  title: "苏州市",
                },
              ],
            },
          ],
        },
      });
    </script>
  </body>
</html>
